<?php

namespace App\Repository\Repositories;

use App\Http\Service\EncryptionService;
use App\Models\StoreCart;
use App\Models\StoreOrder;
use App\Repository\RepositoryInterface\ProductBoundInterface;

//商品自提
class ProductBoundRepositories implements ProductBoundInterface
{
    /**
     * @param $id
     * @param $status
     * @return mixed
     * @throws \Exception
     */
    public function status($id, $status)
    {
        return StoreOrder::updateStatus($id, $status);
    }

    /**
     * 订单查询
     * @param $id
     * @return mixed
     * @throws \Exception
     */
    public function goods($id)
    {

        $id=EncryptionService::passport_decrypt("$id","1911A电商项目");
        $Info = StoreOrder::join('store_cart', 'store_order.cart_id', 'store_cart.id')
            ->join('store_product', 'store_cart.product_id', 'store_product.id')
            ->select('store_order.id', 'pay_price', 'postage', 'image', 'store_name')
            ->where('store_order.uid', $id)->where('store_order.status', "1")->get();
        if (!$Info) {
            throw  new  \Exception('查询失败');
        }
        return $Info;
    }

    /**
     * 配送列表
     */
    public function orderList()
    {
        try {
            $data = StoreOrder::orderPage(10);
            return $data;
        } catch (\Exception $exception) {
            return ['code' => 2001, 'msg' => $exception->getMessage(), 'data' => []];
        }

    }

    /**
     * 提货
     */
    public function delivery($id)
    {

        $id=EncryptionService::passport_decrypt("$id","1911A电商项目");
        $res = StoreOrder::orderSend($id);
        return $res;
    }
}
